package practice;

/**
 * @Description: https://leetcode.cn/problems/container-with-most-water/
 * @Author Ammar
 * @Create 2023/7/22 21:52
 */
public class _11_盛最多睡的容器 {
    public int maxArea(int[] height) {
        int l = 0;
        int r = height.length - 1;
        int water = 0;
        while (l < r) {
            if (height[l] <= height[r]) {
                int minH = height[l];
                water = Math.max(minH * (r - l), water);
                while (++l < r && height[l] <= minH);
            } else {
                int minH = height[r];
                water = Math.max(minH * (r - l), water);
                while (--r > l && height[r] <= minH);
            }
        }
        return water;
    }
}
